<!DOCTYPE html>
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>大客户信息列表</title>
    <!--{include file='comm/icheck.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_region.tpl'}-->

    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>
<body>

<style>
    .imageSites{
        position: absolute;
        left:340px;
        top:56px;
    }
</style>

<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                    <table style="table-layout:fixed;width:100%;">
                        <tbody>
                        <tr>
                            <td>
                                <span>
                                    公司名称：<input type="text"  class="form-control input-sm" name="company_name" id="company_name" style="width:150px;"/>
                                </span>
                                <span>
                                   联系人：<input type="text"  class="form-control input-sm" name="connect_name" id="connect_name" style="width:150px;"/>
                                </span>
                                <span>
                                    省市区：
                                    <select class="form-control " id="province_list" name="province_id" style="width: 100px;margin-right: 5px;">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control " id="city_list" name="city_id" style="width: 100px;margin-right: 5px;">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control " id="county_list" name="country_id" style="width: 100px;">
                                        <option value="">请选择</option>
                                    </select>
                                </span>
                            </td>

                            </tr>

                            <tr>
                                <td style="width: 60px;">
                                    <span>
                                        部 门：
                                    </span>
                                    <span style="vertical-align: middle">
                                        <div class="search_option">
                                            <div class="search_option_drop" >
                                                <span id="searchOptions">
                                                    请选择
                                                <font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                                                </span>
                                            </div>

                                            <ul class="search_option_panel"  id="searchPanels" style="display: none;z-index: 100;">
                                                <li class="childSelectImg" departmentID="" style="margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >请选择</li>
                                                <!--{$department_select_html}-->
                                            </ul>

                                            <input type="hidden" value="0" id="hdnSearchTypes" name="hdnSearchType">
                                            <input type="hidden" value="" id="search_departmentID" name="search_departmentID">
                                            <!--<input type="hidden" value="" id="departmentName" name="departmentName">-->
                                        </div>
                                    </span>
                                    <span>
                                   销售员：<select class="form-control w150" id="userID" name="userID">
                                            <option value="">请选择</option>
                                        </select>
                                </span>
                                    <!--
                                    <span>
                                        属性：
                                        <select class="form-control w150" id="properties" name="properties">
                                            <option value="">请选择</option>
                                            <option value="0">新客户</option>
                                            <option value="1">驳回</option>
                                            <option value="2">老客户</option>
                                        </select>
                                    </span>
                                    -->
                                    <span>
                                        <button type="button" class="btn btn-primary" id="searchBtn" onclick="company.search();">查询</button>
                                    </span>
                                    <span>
                                        <button type="button" class="btn btn-warning" id="clearBtn" onclick="company.clearUp();" >重置</button>
                                    </span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">

$("#flex").flexigrid({
    url:"/invokingAjax-backend/company/company.ajax?operFlg=1",
    dataType: "json",
    colModel : [
        {display: "操作", width : 200, align: 'center'},
	    //{display: "属性", width : 80, align:"center" },
        {display: "公司名称", name : "company_id", sortable : true,width : 150,align:"left"},
        {display: "联系人", width : 80},
        {display: "地址 ", width : 200},
        {display: "手机号码", width : 90 , align:"center"},
        //{display: "联系电话", width: 100 , align:"center"},
        //{display: "公司部门", width :200 , align:"left"},
        //{display: "企业人数", width: 70 , align:"left"},
        //{display: "公司行业", width: 100 , align:"left"},
        //{display: "公司性质", width: 100 , align:"left"},
        {display: "部门", width: 150 , align:"left"},
        {display: "销售员", width: 100 , align:"left"},
        {display: "备注", width: 300 , align:"left"},
        {display: "使用状态", width : 70 , align:"center"}
    ],

    <!--{if $edit_permission}-->
    buttons : [
        {name: "添加", bclass: "add", onpress : "company.add.open"},
        {separator: true},
        //{name: "删除", bclass: "delete", onpress : "company.del.check"},
        //{separator: true},
        //{name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        //{separator: true},
        //{name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
    ],
    <!--{/if}-->
    sortname: "company_id ",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,

    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }

});

var company = {

    //搜索
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },



    //添加大客户信息
    add:{
        open:function(){
            E.open("/quanliadmin/app/company/company.pscript?operFlg=2", "" , {height: 500,width:880, top: 50, left: 250});
        }
    },

    //编辑大客户信息
    edit:{
        open:function( company_id,properties ){
            E.open("/quanliadmin/app/company/company.pscript?operFlg=2&company_id=" + company_id + "&properties=" +properties, "" , {height: 500,width:880, top: 50, left: 250});
        }
    },

    //订单新增
    link:{
        open:function( pcustID,city_id,properties ){
            window.open("/quanliadmin/app/bill/billEdit.pscript?operFlg=3&operateType=1&bill_type=9&pcustID=" + pcustID + "&cityid=" +city_id + "&properties=" +properties);
        }
    },

    del: {

        p_array: '',

        check: function() {

            var p_obj = $('#flex').find('tr.trSelected');
            if (p_obj.length == 0) {
                E.alert('请选择要删除的大客户信息');
            } else {

                var temp_array = new Array();
                var error_flg = 0;

                $.each(p_obj, function(k, v) {
                    var id = $(v).attr('id').replace('row', '');

                    temp_array.push($(v).attr('id').replace('row', ''));
                });

                this.p_array = temp_array;
                E.confirm('您确认要删除选中的大客户信息吗？', 'company.del.execute');

            }

        },

        execute: function() {
            E.loadding.open('正在删除，请稍候...');
            E.ajax_post({
                url: '/invokingAjax-backend/company/company.ajax?operFlg=100&act=del',
                data: {
                    p_array: this.p_array
                },
                call: 'company.del.result'
            });
        },

        result: function( o ) {

            E.loadding.close();
            if (o.code == 200) {
                E.alert('删除成功', 2, 'company.load');
            } else {
                E.alert(o.message);
            }

        }

    },

    change: {

        check: function( company_id, flg ) {

            this.company_id = company_id;
            this.flg = flg;
            if (flg) {
                E.confirm('您确认禁用该大客户信息吗？', 'company.change.execute');
            } else {
                E.confirm('您确认启用该大客户信息吗？', 'company.change.execute');
            }

        },

        execute: function() {

            E.ajax_get({
                url: '/invokingAjax-backend/company/company.ajax?operFlg=100&act=change',
                data: {
                    company_id: this.company_id,
                    flg: this.flg
                },
                call: 'company.change.result'
            });

        },

        result: function( o ) {

            if (o.code == 200) {
                E.alert(o.message, 2, 'company.load');
            } else {
                E.alert(o.message);
            }

        }

    },
        check: function(t){
              this.companyID = t;
                E.confirm("您确认转为老客户吗？", "company.confirmCheck");
        },

    confirmCheck: function() {
        E.ajax_get({
            url: "/invokingAjax-backend/company/company.ajax?operFlg=3",
            data: {
                companyID: this.companyID
            },
            call: "company.result"
        });
    },
    result: function( o ) {
        if (o.code == 200) {
            E.alert(o.message, 2);
            company.search();
        } else {
            E.alert(o.message);
        }
    },

    clearUp:function(){
        $("#connect_name").val('');
        $("#company_name").val('');
        $("#userName").val('');
        $("#province_list").val('');
        $("#city_list").val('');
        $("#county_list").val('');
        E.region.clearC("city_list");
        E.region.clearA("county_list");
        $("#searchPanels").val('');
        $("#search_departmentID").val('');
        $("#userID").val('');
        $("#properties").val('');
        var searchOptions= "请选择" +'<font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>';
        $('#searchOptions').html( searchOptions );
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },

    load: function() {
        $("#flex").flexReload();
    }

};

////显示省市区
E.region.init();


$(window).ready(function() {


    $('#searchPanels').find('li').click(function() {

        var departmentID = $(this).attr('departmentID');
        if (departmentID > 0) {

            E.ajax_get({
                url: '/invokingAjax-backend/company/company.ajax?operFlg=2',
                data: {
                    departmentID: departmentID
                },
                call: function( o ) {

                    if (o.code == 200) {

                        var html = '<option value="">请选择</option>';
                        if ( o.data ) {
                            $.each( o.data, function( k, v ) {
                                html += '<option value="' + v.userID + '">' + v.trueName + '</option>';
                            });
                        }
                        $('#userID').html(html);

                    } else {

                        E.alert( o.message);

                    }

                }
            });

        } else {
            var html = '<option value="">请选择</option>';
            $('#userID').html(html);
        }

    });

});


function openRecord (companyId) {
    E.open("/quanliadmin/app/company/company.pscript?operFlg=4&companyId="+companyId, "", {height: 620,width: 1024, top: 10, left: 150});
}

function openCost (companyId) {
    E.open("/quanliadmin/app/bill/billCost.pscript?operFlg=2&companyId="+companyId, "", {height: 620,width: 1024, top: 10, left: 150});

}
</script>

</body>

</html>